<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="提交人" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入提交人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提交时间" prop="pushTime">
        <el-date-picker
          v-model="createTimeRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择处理状态" clearable>
          <el-option
            v-for="dict in dict.type.suggess_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="suggestList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="ID" align="center" prop="id"  width="120"/>
      <el-table-column label="内容" align="center" prop="content" width="210">
        <template slot-scope="scope">
          <div class="column-content" :title="scope.row.content">
             {{scope.row.content}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="提交人" align="center" prop="userName">
      </el-table-column>
      <el-table-column label="是否匿名" align="center" prop="isAnonymity">
        <template slot-scope="scope">
          {{scope.row.isAnonymity == 0 ? '否' : '是'}}
        </template>
      </el-table-column>
      <el-table-column label="处理状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.suggess_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="是否置顶" align="center" prop="isTop">
        <template slot-scope="scope">
          {{scope.row.isTop == 0 ? '否' : '是'}}
        </template>
      </el-table-column>
      <el-table-column label="是否公示" align="center" prop="isPublish">
        <template slot-scope="scope">
          {{scope.row.isPublish == 0 ? '否' : '是'}}
        </template>
      </el-table-column>
      <el-table-column label="提交时间" align="center" prop="pushTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.pushTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['examine:suggest:edit']"
          >查看</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['examine:suggest:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listSuggest, getSuggest, delSuggest, addSuggest, updateSuggest } from "@/api/examine/suggest";
import {common} from "../learning/common";

export default {
  name: "Suggest",
  mixins:[common],
  dicts: ['suggess_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 意见建议表格数据
      suggestList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: '',
        isShowAnonymity:1,
        status
      },
      createTimeRange:null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询意见建议列表 */
    getList() {
      this.loading = true;
      let dateParams = this.getTimeRange(this.createTimeRange)
      let queryParams = {...this.queryParams,...dateParams}
      listSuggest(queryParams).then(response => {
        this.suggestList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTimeRange = ''
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleDetail(row) {
      this.$router.push({path: "/suggest/detail",query: {id: row.id}});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除意见建议编号为"' + ids + '"的数据项？').then(function() {
        return delSuggest(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('examine/suggest/export', {
        ...this.queryParams
      }, `suggest_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" >
  .column-content{
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }
</style>
